package com.example.innovate.service.impl;

import com.example.innovate.domain.CompetitionRefuseDO;
import com.example.innovate.domain.CompetitionRefuseDOExample;
import com.example.innovate.mapper.CompetitionRefuseDOMapper;
import com.example.innovate.service.CompetitionRefuseService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class CompetitionRefuseServiceImpl implements CompetitionRefuseService {

    @Autowired
    CompetitionRefuseDOMapper competitionRefuseDOMapper;

    @Override
    public void addRefuse(CompetitionRefuseDO competitionRefuseDO) {
        competitionRefuseDOMapper.insertSelective(competitionRefuseDO);
    }

    @Override
    public List<CompetitionRefuseDO> findAllByClass(String className, int pageNumber, int pageSize) {
        CompetitionRefuseDOExample competitionRefuseDOExample = new CompetitionRefuseDOExample();
        competitionRefuseDOExample.createCriteria().andRefuseClassNameEqualTo(className);
        PageHelper.startPage(pageNumber,pageSize);
        return competitionRefuseDOMapper.selectByExample(competitionRefuseDOExample);
    }

    @Override
    public List<CompetitionRefuseDO> findByUserId(int id) {
        CompetitionRefuseDOExample competitionRefuseDOExample = new CompetitionRefuseDOExample();
        competitionRefuseDOExample.createCriteria().andRefuseUserIdEqualTo(id);
        return competitionRefuseDOMapper.selectByExample(competitionRefuseDOExample);
    }

    @Override
    public void deleteRefuse(int id) {
        competitionRefuseDOMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<CompetitionRefuseDO> findAll(String className) {
        CompetitionRefuseDOExample competitionRefuseDOExample = new CompetitionRefuseDOExample();
        competitionRefuseDOExample.createCriteria().andRefuseClassNameEqualTo(className);
        return competitionRefuseDOMapper.selectByExample(competitionRefuseDOExample);
    }
}
